package com.yitongmao.activity;

import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.yitongmao.bean.OrderDetailsBean;
import com.yitongmao.core.cache.ACache;
import com.yitongmao.yitmfruit.R;

import butterknife.Bind;
import butterknife.ButterKnife;

public class OrderDetailsActivity extends AppCompatActivity {

    @Bind(R.id.maddressName)
    TextView maddressName;
    @Bind(R.id.maddressPhone)
    TextView maddressPhone;
    @Bind(R.id.maddressDetails)
    TextView maddressDetails;
    @Bind(R.id.mDetailsImage)
    ImageView mDetailsImage;
    @Bind(R.id.mDetailsTitle)
    TextView mDetailsTitle;
    @Bind(R.id.mDetailsPrice)
    TextView mDetailsPrice;
    @Bind(R.id.mDetailsDanHao)
    TextView mDetailsDanHao;
    @Bind(R.id.mDetailsDownTime)
    TextView mDetailsDownTime;
    @Bind(R.id.mDetailsPayLeiXing)
    TextView mDetailsPayLeiXing;
    @Bind(R.id.mDetailsPayWay)
    TextView mDetailsPayWay;
    @Bind(R.id.mDetailsHuMing)
    TextView mDetailsHuMing;
    @Bind(R.id.mDetailsZhangHao)
    TextView mDetailsZhangHao;
    @Bind(R.id.mDetailsOpenHu)
    TextView mDetailsOpenHu;
    @Bind(R.id.mDetailsLianHangHao)
    TextView mDetailsLianHangHao;
    @Bind(R.id.mDetailsShiBieMa)
    TextView mDetailsShiBieMa;
    @Bind(R.id.mDetailsPeiSongWay)
    TextView mDetailsPeiSongWay;
    @Bind(R.id.mDetailsTaiTouLeiXing)
    TextView mDetailsTaiTouLeiXing;
    @Bind(R.id.mDetailsTaiTouMingCheng)
    TextView mDetailsTaiTouMingCheng;
    @Bind(R.id.mDetailsPayPrice)
    TextView mDetailsPayPrice;
    @Bind(R.id.btn_back)
    Button btnBack;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        immerSion();
        setContentView(R.layout.activity_order_details);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        btnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                OrderDetailsActivity.this.finish();
            }
        });
        Gson gson = new Gson();
        String orderdetails = ACache.get(OrderDetailsActivity.this).getAsString("orderdetails");
        OrderDetailsBean orderDetailsBean = gson.fromJson(orderdetails, OrderDetailsBean.class);
        if (orderDetailsBean != null) {
            String provinceName = orderDetailsBean.dateilMap.get(0).address.provinceName;
            String cityName = orderDetailsBean.dateilMap.get(0).address.cityName;
            String countryName = orderDetailsBean.dateilMap.get(0).address.countryName;
            String name = orderDetailsBean.dateilMap.get(0).address.name;
            String phone = orderDetailsBean.dateilMap.get(0).address.phone;
            String detailsimage = orderDetailsBean.dateilMap.get(0).orderGood.get(0).goodsThumb;
            String title = orderDetailsBean.dateilMap.get(0).orderGood.get(0).title;
            String tradePrice = String.valueOf(orderDetailsBean.dateilMap.get(0).orderGood.get(0).tradePrice);
            String number = String.valueOf(orderDetailsBean.dateilMap.get(0).orderGood.get(0).number);
            /*int i = Integer.parseInt(number);
            int price = Integer.parseInt(tradePrice);
            int i1 = i * price;
            String sum = String.valueOf(i1);*/
            String orderCode = String.valueOf(orderDetailsBean.dateilMap.get(0).orderCode);
            String createTime = String.valueOf(orderDetailsBean.dateilMap.get(0).createTime);
            String payType = String.valueOf(orderDetailsBean.dateilMap.get(0).payType);
            String companyName = String.valueOf(orderDetailsBean.dateilMap.get(0).account.companyName);
            String account = String.valueOf(orderDetailsBean.dateilMap.get(0).account.account);
            String openingBank = String.valueOf(orderDetailsBean.dateilMap.get(0).account.openingBank);
            String unionLine = String.valueOf(orderDetailsBean.dateilMap.get(0).account.unionLine);
            String remittanceCode = String.valueOf(orderDetailsBean.dateilMap.get(0).remittanceCode);
            //String remittanceCode =String.valueOf(orderDetailsBean.dateilMap.get(0).remittanceCode);
            //int i = Integer.parseInt(tradePrice) * Integer.parseInt(number);
            //String sumPrice = String.valueOf(i);
            maddressName.setText(name);
            maddressPhone.setText(phone);
            maddressDetails.setText(provinceName + "" + cityName + "" + countryName);
            Glide.with(OrderDetailsActivity.this).load(detailsimage).into(mDetailsImage);
            mDetailsTitle.setText(title);
            mDetailsPrice.setText("￥" + tradePrice + "万/吨");
            mDetailsDanHao.setText(orderCode);
            mDetailsDownTime.setText(createTime);
            mDetailsPayLeiXing.setText(payType);
            mDetailsHuMing.setText(companyName);
            mDetailsZhangHao.setText(account);
            mDetailsOpenHu.setText(openingBank);
            mDetailsLianHangHao.setText(unionLine + "（非必填）");
            mDetailsShiBieMa.setText(remittanceCode);
            //mDetailsPayPrice.setText();
        }
    }

    //沉浸式状态栏
    public void immerSion() {
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
            window.setNavigationBarColor(Color.BLACK);
        }
    }
}
